var CreatedOKLodop7766=null;
var conf = {
	'full_name' : WG.fullname,
	'address' : WG.address,
	'telephone' : WG.telephone,
};

//==本JS是加载Lodop插件或Web打印服务CLodop/Lodop7的综合示例，可直接使用，建议理解后融入自己程序==

//用双端口加载主JS文件Lodop.js(或CLodopfuncs.js兼容老版本)以防其中某端口被占:
const MainJS ="CLodopfuncs.js";
URL_WS1   = "ws://localhost:8000/"+MainJS,                //ws用8000/18000
	URL_WS2   = "ws://localhost:18000/"+MainJS,
	URL_HTTP1 = "http://localhost:8000/"+MainJS,              //http用8000/18000
	URL_HTTP2 = "http://localhost:18000/"+MainJS,
	URL_HTTP3 = "https://localhost.lodop.net:8443/"+MainJS;   //https用8000/8443
var CreatedOKLodopObject, CLodopIsLocal, LoadJsState;

//==判断是否需要CLodop(那些不支持插件的浏览器):==
function needCLodop() {
	try {
		var ua = navigator.userAgent;
		if (ua.match(/Windows\sPhone/i) ||
			ua.match(/iPhone|iPod|iPad/i) ||
			ua.match(/Android/i) ||
			ua.match(/Edge\D?\d+/i))
			return true;
		var verTrident = ua.match(/Trident\D?\d+/i);
		var verIE = ua.match(/MSIE\D?\d+/i);
		var verOPR = ua.match(/OPR\D?\d+/i);
		var verFF = ua.match(/Firefox\D?\d+/i);
		var x64 = ua.match(/x64/i);
		if ((!verTrident) && (!verIE) && (x64)) return true;
		else if (verFF) {
			verFF = verFF[0].match(/\d+/);
			if ((verFF[0] >= 41) || (x64)) return true;
		} else if (verOPR) {
			verOPR = verOPR[0].match(/\d+/);
			if (verOPR[0] >= 32) return true;
		} else if ((!verTrident) && (!verIE)) {
			var verChrome = ua.match(/Chrome\D?\d+/i);
			if (verChrome) {
				verChrome = verChrome[0].match(/\d+/);
				if (verChrome[0] >= 41) return true;
			}
		}
		return false;
	} catch (err) {
		return true;
	}
}

//==检查加载成功与否，如没成功则用http(s)再试==
//==低版本CLODOP6.561/Lodop7.043及前)用本方法==
function checkOrTryHttp() {
	if (window.CLODOP2015_7028) {
		LoadJsState = "complete";
		return true;
	}
	if (LoadJsState == "loadingB" || LoadJsState == "complete") return;
	LoadJsState = "loadingB";
	var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
	var JS1 = document.createElement("script")
		,JS2 = document.createElement("script")
		,JS3 = document.createElement("script");
	JS1.src = URL_HTTP1;
	JS2.src = URL_HTTP2;
	JS3.src = URL_HTTP3;
	JS1.onload = JS2.onload = JS3.onload = JS2.onerror = JS3.onerror=function(){LoadJsState = "complete";}
	JS1.onerror = function(e) {
		if (window.location.protocol !== 'https:')
			head.insertBefore(JS2, head.firstChild); else
			head.insertBefore(JS3, head.firstChild);
	}
	head.insertBefore(JS1,head.firstChild);
}

//==加载Lodop对象的主过程:==
(function loadCLodop(){
	if (!needCLodop()) return;
	CLodopIsLocal = !!((URL_WS1 + URL_WS2).match(/\/\/localho|\/\/127.0.0./i));
	LoadJsState = "loadingA";
	if (!window.WebSocket && window.MozWebSocket) window.WebSocket=window.MozWebSocket;
	//ws方式速度快(小于200ms)且可避免CORS错误,但要求Lodop版本足够新:
	try {
		var WSK1=new WebSocket(URL_WS1);
		WSK1.onopen = function(e) { setTimeout("checkOrTryHttp();",200); }
		WSK1.onmessage = function(e) {if (!window.CLODOP2015_7028) eval(e.data);}
		WSK1.onerror = function(e) {
			var WSK2=new WebSocket(URL_WS2);
			WSK2.onopen = function(e) {setTimeout("checkOrTryHttp();",200);}
			WSK2.onmessage = function(e) {if (!window.CLODOP2015_7028) eval(e.data);}
			WSK2.onerror= function(e) {checkOrTryHttp();}
		}
	} catch(e){
		checkOrTryHttp();
	}
})();

//==获取LODOP对象主过程,判断是否安装、需否升级:==
function getLodop(oOBJECT, oEMBED) {
	var strFontTag = "<br><font color='#FF00FF'>打印控件";
	var strLodopInstall = strFontTag + "未安装!点击这里<a href='install_lodop32.exe' target='_self'>执行安装</a>";
	var strLodopUpdate = strFontTag + "需要升级!点击这里<a href='install_lodop32.exe' target='_self'>执行升级</a>";
	var strLodop64Install = strFontTag + "未安装!点击这里<a href='install_lodop64.exe' target='_self'>执行安装</a>";
	var strLodop64Update = strFontTag + "需要升级!点击这里<a href='install_lodop64.exe' target='_self'>执行升级</a>";
	var strCLodopInstallA = "<br><font color='#FF00FF'>Web打印服务CLodop未安装启动，点击这里<a href='CLodop_Setup_for_Win32NT.exe' target='_self'>下载执行安装</a>";
	var strCLodopInstallB = "<br>（若此前已安装过，可<a href='CLodop.protocol:setup' target='_self'>点这里直接再次启动</a>）";
	var strCLodopUpdate = "<br><font color='#FF00FF'>Web打印服务CLodop需升级!点击这里<a href='CLodop_Setup_for_Win32NT.exe' target='_self'>执行升级</a>";
	var strLodop7FontTag = "<br><font color='#FF00FF'>Web打印服务Lodop7";
	var strLodop7HrefX86 = "点击这里<a href='Lodop7_Linux_X86_64.tar.gz' target='_self'>下载安装</a>(下载后解压，点击lodop文件开始执行)";
	var strLodop7HrefARM = "点击这里<a href='Lodop7_Linux_ARM64.tar.gz'  target='_self'>下载安装</a>(下载后解压，点击lodop文件开始执行)";
	var strLodop7Install_X86 = strLodop7FontTag + "未安装启动，" + strLodop7HrefX86;
	var strLodop7Install_ARM = strLodop7FontTag + "未安装启动，" + strLodop7HrefARM;
	var strLodop7Update_X86 = strLodop7FontTag + "需升级，" + strLodop7HrefX86;
	var strLodop7Update_ARM = strLodop7FontTag + "需升级，" + strLodop7HrefARM;
	var strInstallOK = "，成功后请刷新本页面或重启浏览器。</font>";
	var LODOP;
	try {
		var isWinIE = (/MSIE/i.test(navigator.userAgent)) || (/Trident/i.test(navigator.userAgent));
		var isWinIE64 = isWinIE && (/x64/i.test(navigator.userAgent));
		var isLinuxX86 = (/Linux/i.test(navigator.platform)) && (/x86/i.test(navigator.platform));
		var isLinuxARM = (/Linux/i.test(navigator.platform)) && (/aarch/i.test(navigator.platform));

		if (needCLodop() || isLinuxX86 || isLinuxARM) {
			try {
				LODOP = window.CLODOP2015_7028;
			} catch (err) {}
			if (!LODOP && LoadJsState !== "complete") {
				if (LoadJsState == "loading")
					alert("网页还没下载完毕，请稍等一下再操作."); else
					alert("未曾加载Lodop主JS文件，请先调用loadCLodop过程.");
				return;
			}
			var strAlertMessage;
			if (!LODOP) {
				if (isLinuxX86)
					strAlertMessage = strLodop7Install_X86;
				else if (isLinuxARM)
					strAlertMessage = strLodop7Install_ARM;
				else
					strAlertMessage = strCLodopInstallA + (CLodopIsLocal ? strCLodopInstallB : "");
				document.body.innerHTML = strAlertMessage + strInstallOK + document.body.innerHTML;
				return;
			} else {
				if (isLinuxX86 && LODOP.CVERSION < "7.0.4.3")
					strAlertMessage = strLodop7Update_X86;
				else if (isLinuxARM && LODOP.CVERSION < "7.0.4.3")
					strAlertMessage = strLodop7Update_ARM;
				else if (CLODOP.CVERSION < "6.5.6.4")
					strAlertMessage = strCLodopUpdate;

				if (strAlertMessage)
					document.body.innerHTML = strAlertMessage + strInstallOK + document.body.innerHTML;
			}
		} else {
			//==如果页面有Lodop插件就直接使用,否则新建:==
			if (oOBJECT || oEMBED) {
				if (isWinIE)
					LODOP = oOBJECT;
				else
					LODOP = oEMBED;
			} else if (!CreatedOKLodopObject) {
				LODOP = document.createElement("object");
				LODOP.setAttribute("width", 0);
				LODOP.setAttribute("height", 0);
				LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
				if (isWinIE)
					LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
				else
					LODOP.setAttribute("type", "application/x-print-lodop");
				document.documentElement.appendChild(LODOP);
				CreatedOKLodopObject = LODOP;
			} else
				LODOP = CreatedOKLodopObject;
			//==Lodop插件未安装时提示下载地址:==
			if ((!LODOP) || (!LODOP.VERSION)) {
				document.body.innerHTML = (isWinIE64 ? strLodop64Install : strLodopInstall) + strInstallOK + document.body.innerHTML;
				return LODOP;
			}
			if (LODOP.VERSION < "6.2.2.6") {
				document.body.innerHTML = (isWinIE64 ? strLodop64Update : strLodopUpdate) + strInstallOK + document.body.innerHTML;
			}
		}
		//===如下空白位置适合调用统一功能(如注册语句、语言选择等):=======================

		LODOP.SET_LICENSES("","13528A153BAEE3A0254B9507DCDE2839","EDE92F75B6A3D917F65910","D60BC84D7CF2DE18156A6F88987304CB6D8");
		//===============================================================================
		return LODOP;
	} catch (err) {
		alert("getLodop出错:" + err);
	}
}


var printType = new Object;
printType.defaults = 'Epson WF-C5290a'; //默认打印机A4
printType.retail = '中盈税之星 QS-312K';  //销售单打印
printType.product = 'Epson WF-C5290a';  //产品标签打印

/**
* 打印html
*/
function lodop_print_html(title,html,printer,width,height)
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.ADD_PRINT_HTM(0, 0,'100%','100%', html);
	LODOP.PREVIEW();
}

/**
* 预览
*/
function lodop_preview_html(title,html,printer,width,height)
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.ADD_PRINT_HTM(0, 0,'100%','100%', html);
	
	LODOP.PREVIEW();
}

/**
* 获取打印机名称
*/
function lodop_get_printer_name()
{
	LODOP = getLodop();
	var iPrinterCount=LODOP.GET_PRINTER_COUNT();
	var arrList = new Array();
	for(var i=0;i<iPrinterCount;i++)
	{
		arrList.push(LODOP.GET_PRINTER_NAME(i));
	};
	return arrList;
}

/**
* 按坐标打印
*/
function lodop_coordinate_print(title,coordinate,printer,width,height) 
{
	LODOP = getLodop();
	LODOP.PRINT_INIT(title); // 初始化
	if(printer)
	{
		// 指定打印机
		LODOP.SET_PRINTER_INDEX(printer); 
	}
	
	//打印纸张尺寸
	width = width + 'mm';
	
	if(height == ""){
		height = "100%"
	}else{
		height = height + 'mm'
	}
	
	LODOP.SET_PRINT_PAGESIZE(1,width,height,'CreateCustomPage');
	
	LODOP.PREVIEW();
}

/**
* 打印销售单-科视
*/
function createRetailPrinter(d) 
{
		var tables = '<div class="print_template">\
		<div class="caption">'+ conf.full_name +'</div>\
	<table class="notables topnotables">\
	  <tr><td  width="5%">配镜单号：</td><td><span id="ManualNumber"></span></td>\
	    <td nowrap="nowrap">配镜日期：</td>\
	    <td nowrap="nowrap"><span id="RCreatedAt"></span></td>\
	    <td nowrap="nowrap">取镜日期：</td>\
	    <td nowrap="nowrap"><span id="QjDate"></span></td>\
      </tr>\
	  <tr><td  width="5%">顾客姓名：</td><td><span id="Realname"></span></td><td nowrap="nowrap">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</td><td><span id="Sex"></span></td><td>出生年月：</td><td nowrap="nowrap"><span id="Birthday"></span></td></tr>\
	  <tr><td nowrap="nowrap">移动电话：</td><td nowrap="nowrap"><span id="Mobile"></span></td>\
	    <td  width="5%">联系地址：</td>\
	    <td colspan="3"><span id="Address" class="w100" style="width:95%;"></span></td>\
      </tr>\
	</table>\
    <table class="tables" style="margin-top:10px;" data-type="chufang">\
    <tr><td>眼别</td><td>球镜</td><td>柱镜</td><td>轴位</td><td>近瞳距(mm)</td><td>远瞳距(mm)</td><td>瞳高(mm)</td><td>裸眼</td><td>矫正</td><td>ADD</td><td>通道</td><td>棱镜</td><td>基底</td></tr>\
    <tr data-type="right"><td>右眼</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="pd_yuan"></td><td data-type="pd_yuan"></td><td data-type="mrp"></td><td data-type="nv"></td><td data-type="cv"></td><td data-type="add_info"></td><td data-type="pass"></td><td data-type="v"></td><td data-type="bc"></td></tr>\
    <tr data-type="left"><td>左眼</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="pd_yuan"></td><td data-type="pd_yuan"></td><td data-type="mrp"></td><td data-type="nv"></td><td data-type="cv"></td><td data-type="add_info"></td><td data-type="pass"></td><td data-type="v"></td><td data-type="bc"></td></tr>\
	</table>\
    <table class="tables" style="margin-top:10px;margin-bottom:10px;">\
      <tr><td colspan="6" style="text-align:center; font-size:15px;">商品信息</td></tr>\
      <tr><td></td><td>商品名称</td><td>数量</td><td>单位</td><td>零售价</td><td>小计</td></tr>\
      <tbody id="databody"></tbody>\
    </table>\
	<table class="notables" width="100%">\
	  <tr><td width="5%">付款方式：</td><td colspan="7"><span id="fukuanfs" class="w100"></span></td><td width="5%">总计价格：</td><td><span id="zhongjijiage"></span></td><td width="5%">调减金额：</td><td><span id="tiaojianje"></span></td></tr>\
	  <tr><td width="5%">验&nbsp;&nbsp;光&nbsp;&nbsp;师：</td><td width="5%"><span id="yanguangshi"></span></td><td>销&nbsp;&nbsp;售&nbsp;&nbsp;员：</td><td width="5%"><span id="xiaoshouyuan"></span></td><td>收&nbsp;&nbsp;银&nbsp;&nbsp;员：</td><td width="5%"><span id="shouyingyuan"></span></td><td>加&nbsp;&nbsp;工&nbsp;&nbsp;师：</td><td><span id="jiagongyuan"></span></td><td width="5%">小计价格：</td><td><span id="xiaojiejine"></span></td><td width="5%">实收金额：</td><td><span id="shishoujine"></span></td></tr>\
	  <tr><td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</td><td colspan="7"><span id="beizhu" class="w100"></span></td><td></td><td colspan="3"></td></tr>\
	  <tr><td>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</td><td colspan="7"><span  class="w100" id="dizhi"></span></td><td>电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话：</td><td colspan="3"><span class="w100" id="dianhua"></td></tr>\
	</table>\
	</div>';

		LODOP=getLodop();
		//LODOP.PRINT_INITA(0,0,"210.08mm","145.79mm","销售单打印");
    	LODOP.SET_PRINT_PAGESIZE(0,"210.08mm","145.79mm","A4");
    	LODOP.SET_PRINTER_INDEX(printType.retail);
    	LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);

    	var tabJquery = $(tables); //表格转成JQ对象

    	tabJquery.find('#theader').html('<b>'+ conf.full_name +'</b>');
		
    	tabJquery.find('#dizhi').html(conf.address );
    	tabJquery.find('#dianhua').html(conf.telephone);

		setHtml = function(d) {
			$.each(d, function(k,v){
				if(k == 'CreatedAt'&&d.BusinessId) {
                    tabJquery.find('#RCreatedAt').html(timetransDate(v));
				} else if(k == 'TotalMoney') {
                    tabJquery.find('#TotalMoney').html(v);
                    tabJquery.find('#TotalMoneyBig').html(smalltoBIG(v));
				}else {
					if(tabJquery.find('#'+k)) {
                        tabJquery.find('#'+k).html(v);
					}
				}
			});
		};
		//客户资料
		if(d.archives) {
			setHtml(d.archives);
		}
		//验光数据
		if(d.optometry) {
			if(d.optometry.chufang) {
				var box = tabJquery.find('[data-type="chufang"]');
				$.each(d.optometry.chufang, function (idx, value) {
					$.each(value, function (xx, val) {
						$.each(val, function (cc, vv) {
							box.find('[data-type="'+ xx +'"]').find('[data-type="'+ cc +'"]').html(vv);
						});
					});
				});
			}
		}
		//付款方式	
		if(d.retail.AlreadyMoney > 0) {
			fukuanfs = '';
			if(d.retail.AlipayMoney>0) {
				fukuanfs += '支付宝：'+toDecimal2(d.retail.AlipayMoney);
			}
			if(d.retail.WechatMoney>0) {
				fukuanfs += '微信：'+toDecimal2(d.retail.WechatMoney);
			}
			if(d.retail.CardMoney>0) {
				fukuanfs += '刷卡：'+toDecimal2(d.retail.CardMoney);
			}
			if(d.retail.CashMoney>0) {
				fukuanfs += '现金：'+toDecimal2(d.retail.CashMoney);
			}
			tabJquery.find('#fukuanfs').html(fukuanfs);
		} else {
			tabJquery.find('#fukuanfs').html('未付');
		}

		//总计
		tabJquery.find('#zhongjijiage').html(toDecimal2(d.retail.TotalMoney));
		//调减
		tabJquery.find('#tiaojianje').html(toDecimal2(d.retail.ChangesMoney));
		//小计金额
		tabJquery.find('#xiaojiejine').html(toDecimal2(d.retail.SumPayable));
		//实收金额
		tabJquery.find('#shishoujine').html(toDecimal2(d.retail.SumPayable));
		//销售员
		tabJquery.find('#xiaoshouyuan').html(d.retail.BusinessName);
		//验光师
		tabJquery.find('#yanguangshi').html(d.optometry ? d.optometry.Optometrist : '');
		//备注
		tabJquery.find('#beizhu').html(d.retail.Remarks);
		//配镜单号
		tabJquery.find('#ManualNumber').html(d.retail.ManualNumber);
		//配镜日期
		tabJquery.find('#RCreatedAt').html(timetransDate(d.retail.CreatedAt));

		
		//订单数据
		var RetailsDataLength = d.retail_data.length;
		var html = [];
		if(RetailsDataLength > 0) {
		   var rd = d.retail_data;
		   $.each(rd, function(idx, val){
			   html.push('<tr>');
			   html.push('<td>'+ (idx+1) +'</td>');
			   html.push('<td style="text-align:left;">'+ val.Products.Name +'</td>');
			   html.push('<td>'+ val.Amount +'</td>');
			   html.push('<td>'+ val.Products.Unit +'</td>');
			   html.push('<td style="text-align:right;">'+ toDecimal2(val.OriginalPrice) +'</td>');
			   html.push('<td style="text-align:right;">'+ toDecimal2(val.TotalPrice) +'</td>');
			   html.push('</tr>');
		   });
		}
		//产品补充
		cutRetailsDataLength = 5-RetailsDataLength;
		if(cutRetailsDataLength>=1) {
			for(i=1;i<=cutRetailsDataLength;i++) {
				html.push('<tr><td>&nbsp;</td><td></td><td></td><td></td><td></td><td></td></tr>');
			}
		}

		var style = "<style>\
		.print_template{}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse; width:100%;}\
		.caption{ font-size: 16px; padding-bottom: 10px; text-align:center;}\
		.tables tbody {}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 1.3; font-size: 10px;}\
		.tables tfoot td{ font-style: 11px; color: #666d70; padding-top: 10px;}\
		.tables tfoot #fmobile{ text-align: right;}\
		.notables{width: 100%; margin-top: 10px; color: #000; font-size: 10px;}\
		.notables td{font-size: 10px;line-height:20px; height:22px;white-space: nowrap; padding:0px; margin:0px;}\
		.notables .w100{ width:100%;}\
		.notables td span{ border-bottom:1px solid #000; width:60px; display:block;height:20px; text-align:left;overflow:hidden}\
		.topnotables{ margin-top: 0px;}\
		.topnotables td span{width:160px;}\
		</style>";
    	tabJquery.find('#databody').html(html.join(''));

		LODOP.ADD_PRINT_HTM(20,25,'200mm','140mm', style + '<body>' + tabJquery.html() + '</body>');
    	//LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",1);
		//LODOP.PRINT_SETUP();
		//LODOP.PRINTA(); //直接打印
		LODOP.PREVIEW();
}


/**
* 打印验光单-科视
*/
function setOptometryPrinterBoxText(obj, data) {
    var _this = $(obj);
    $.each(data, function (index, value) {
        _this.find('[data-type="'+ index +'"]').text(value);
    });
}
function createOptometryPrinter(d) {
	var tables = '<div class="print_template">\
		<div class="caption">'+ conf.full_name +'验光处方<br />Refrcating Prescription</div>\
	<table class="notables topnotables">\
	  <tr><td width="5%">验光单号（No.）：</td><td width="20%"><span id="DocumentNumber"></span></td>\
	    <td  width="5%" nowrap="nowrap">验光日期（Date）：</td>\
	    <td  width="20%"><span id="RCreatedAt"></span></td>\
	    <td width="5%" nowrap="nowrap">验光师（O.D.）：</td>\
	    <td><span id="Optometrist"></span></td>\
      </tr>\
	  <tr><td>姓名（Name）：</td><td><span id="Realname"></span></td><td nowrap="nowrap">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别（Sex）：</td><td><span id="Sex"></span></td><td>生日（Birthday）：</td><td nowrap="nowrap"><span id="Birthday"></span></td></tr>\
	</table>\
    <table class="tables" style="margin-top:10px;">\
		<tr><td colspan="2"></td><td>球镜<br>Sphere（D）</td><td>柱镜<br>Cylinder</td><td>轴位<br>Axis</td><td>棱镜<br>Prism</td><td>瞳距<br>P.D（mm）</td><td>裸眼<br>B.V.A </td><td>矫正<br>C.V.A</td></tr>\
	  	<tr data-type="far_right"><td rowspan="2">远用<br>Distance</td><td>OD</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td rowspan="2" data-type="total_pd_yuan"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr data-type="far_left"><td>OS</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr data-type="near_right"><td rowspan="2">近用<br>Near</td><td>OD</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td rowspan="2" data-type="total_pd_jin"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr  data-type="near_left"><td>OS</td><td data-type="sph"></td><td data-type="cyl"></td><td data-type="axial_view"></td><td data-type="v"></td><td data-type="nv"></td><td data-type="cv"></td></tr>\
		<tr><td colspan="2">备注<br>Remarks</td><td colspan="7" id="Remarks" style="text-align: left;"></td></tr>\
    </table>\
	<table class="notables" width="100%">\
	  <tr><td width="5%">地址（Address）：</td><td colspan="7"><span  class="w100" id="dizhi"></span></td><td width="5%">电话（Telephone）：</td><td colspan="3"><span class="w100" id="dianhua"></td></tr>\
	</table>\
	</div>';
	/*
	<tr><td rowspan="2" valign="middle">其它（Other）</td><td valign="middle">&nbsp;</td><td>远用瞳距</td><td id="YuanyongTongju"></td><td>瞳高-R</td><td id="RTonggao"></td><td>ADD-R</td><td id="RAdd"></td><td></td></tr>\
		<tr><td valign="middle">&nbsp;</td><td>近用瞳距</td><td id="JinyongTongju"></td><td>瞳高-L</td><td id="LTonggao"></td><td>ADD-L</td><td id="LAdd"></td><td></td></tr>\
	*/
		LODOP=getLodop();
		//LODOP.PRINT_INITA(0,0,"210.08mm","145.79mm","销售单打印");
    	LODOP.SET_PRINT_PAGESIZE(0,"210.08mm","145.79mm","A4");
    	LODOP.SET_PRINTER_INDEX(printType.retail);
    	LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);

    	var tabJquery = $(tables); //表格转成JQ对象

    	tabJquery.find('#theader').html('<b>'+ conf.full_name +'</b>');
		
    	tabJquery.find('#dizhi').html(conf.address);
    	tabJquery.find('#dianhua').html(conf.telephone);

		setHtml = function(d) {
			
			$.each(d, function(k,v){
				if(k == 'CreatedAt') {
                    tabJquery.find('#RCreatedAt').html(timetransDate(v));
				}else if(k =="far" || k =="near") {
					if(v) {
						var data = v;
						if(k =="far") {
							setOptometryPrinterBoxText(tabJquery.find('[data-type="far_right"]'), data['right']);  //右眼
							tabJquery.find('[data-type="far_right"]').find('[data-type="total_pd_yuan"]').text(data['right'].total_pd_yuan);
							setOptometryPrinterBoxText(tabJquery.find('[data-type="far_left"]'), data['left']);  //左眼
						}
						if(k =="near") {
							setOptometryPrinterBoxText(tabJquery.find('[data-type="near_right"]'), data['right']);  //右眼
							setOptometryPrinterBoxText(tabJquery.find('[data-type="near_left"]'), data['left']);  //左眼
							tabJquery.find('[data-type="near_right"]').find('[data-type="total_pd_yuan"]').text(data['right'].total_pd_yuan);
						}
					}
				}else {
					if(tabJquery.find('#'+k)) {
                        tabJquery.find('#'+k).text(v);
					}
				}
			});
		};
		
		//档案数据
		if(d.Archives) {
			setHtml(d.Archives);
			setHtml(d);
		}
		//验光数据
		setHtml(d.chufang);

		var style = "<style>\
		.print_template{}\
		.tables{ border:1px solid #000;border-width:1px 0 0 1px; border-collapse:collapse; width:100%;}\
		.caption{ font-size: 18px; padding-bottom: 10px; text-align:center;}\
		.tables tbody {}\
		.tables tbody td{border:1px solid #000;border-width:0 1px 1px 0; padding:2px; text-align:center; color:#333; line-height: 22px; font-size: 14px;}\
		.tables tfoot td{ font-style: 11px; color: #666d70; padding-top: 10px;}\
		.tables tfoot #fmobile{ text-align: right;}\
		.notables{width: 100%; margin-top: 10px; color: #000; font-size: 10px;}\
		.notables td{font-size: 12px;line-height:23px; height:24px;white-space: nowrap; padding:0px; margin:0px;}\
		.notables .w100{ width:100%;}\
		.notables td span{ border-bottom:1px solid #000; width:60px; display:block;height:23px; text-align:left;overflow:hidden}\
		.topnotables{ margin-top: 0px;}\
		.topnotables td span{width:100%;}\
		</style>";
    	//tabJquery.find('#databody').html(html);
		LODOP.ADD_PRINT_HTM(20,25,'200mm','140mm', style + '<body>' + tabJquery.html() + '</body>');
		LODOP.PREVIEW();
}